#include <string.h>
#include <iostream>
using namespace std;
//实现请结合前面学到的知识完成这个功能：无论是创建多个Computer对象，还是进行Compute
//r对象的复制、赋值，Computer的总价始终能够正确输出
class Computer{
public:
    Computer ( const char *brand,float price)
    :_brand(new char[strlen(brand)+1]())
    ,_price(price)
    {
        strcpy(_brand,brand);
        _totalprice+=price;
    }
    ~Computer(){
        delete [] _brand;
        _brand=nullptr;
    }
    //拷贝构造函数
    Computer(const Computer& rhs)
    :_brand(new char[strlen(rhs._brand)+1]())
    ,_price(rhs._price)
    {
        strcpy(_brand,rhs._brand);
        _totalprice+=_price;
    }
    //赋值运算符函数
    Computer & operator=(const Computer & rhs){
        if(this!=&rhs){
        //进行赋值操作
        delete [] _brand;
        _totalprice-=_price;

        _brand=new char[strlen(rhs._brand)+1]();
        strcpy(_brand,rhs._brand);
        _price=rhs._price;
        _totalprice+=_price;
        }
        return *this;
    }
    static float gettotalprice(){
        return _totalprice;
    }
private:
    char* _brand;
    static float _totalprice;
    float _price;
};
float Computer::_totalprice=0;
void test(){
cout<<Computer::gettotalprice()<<endl;
Computer c1("apple",7800);
cout<<Computer::gettotalprice()<<endl;
Computer c2=c1;
cout<<Computer::gettotalprice()<<endl;
Computer c3("huawei",5600);
cout<<Computer::gettotalprice()<<endl;
c3=c1;
cout<<Computer::gettotalprice()<<endl;
}
int main(int argc, char * argv[]){
    test();
    return 0;
}

